﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="wfCertificateEdit.aspx.cs" Inherits="msBsc.WebUi.ShpMana.wfCertificateEdit1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>资格证详情</title>
    <link href="/themes/wStyle1/css/sLayout.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/sHead.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/sFoot.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/usermenu.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/from.css" rel="stylesheet" />
    <link href="/jqPlugin/hdfu/hdfu.css" rel="stylesheet" />
    <link href="/themes/wStyle1/css/Seller/sReleaseForum.css" rel="stylesheet" />
    <link href="/jqPlugin/kindeditor/themes/default/default.css" type="text/css" rel="stylesheet" />
    <link href="/jqPlugin/layer/skin/layer.css" rel="stylesheet" />
    <link href="/jqPlugin/laydate/skins/default/laydate.css" rel="stylesheet" />
    <style type="text/css">
        .texarea {
            width: 648px;
            height: 150px;
        }

        #logo_img_selected img {
            max-height: 300px;
            /*max-width:150px;*/
        }

        .selCondition li {
            background-color: #f5f5f5;
            border: 1px solid #f5f5f5;
            float: left;
            line-height: 20px;
            margin-right: 5px;
            margin-top: 3px;
            padding: 4px 10px;
        }

        .divMaxCondition {
            display: inline;
            float: left;
            text-align: left;
            width: 720px;
        }

        .cancel {
            cursor: pointer;
            padding-left: 5px;
        }

        .additem {
            margin-left: 10px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="wf_all">
        <input type="hidden" id="crtificateId" />
        <input type="hidden" id="djackId" />
        <div class="main-container">
            <div class="main-Info" id="txtMainInfo" style="margin-bottom: 200px;">
                <div class="main-horizontal">
                    <div class="r_row">
                        <span class="control-span">资格证号<span class="required">*</span></span><div class="controls" id="txtCertificateNumber">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">姓名<span class="required">*</span></span>
                        <div class="controls" id="txtName">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">性别<span class="required">*</span></span>
                        <div class="controls" id="txtGender">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">国籍<span class="required">*</span></span>
                        <div class="controls" id="txtNationId">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">住址<span class="required">*</span></span>
                        <div class="controls">
                            <span id="txtSelCountry"></span>
                            <span id="txtSelCity"></span>
                            <span id="txtSelDestination"></span>
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">出生日期<span class="required">*</span></span>
                        <div class="controls" id="txtBirthDate">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">领证日期<span class="required">*</span></span>
                        <div class="controls" id="txtIssueDate">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">准驾车型<span class="required">*</span></span>
                        <div class="controls" id="txtQuasiType">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">起效日期<span class="required">*</span></span>
                        <div class="controls" id="txtEffStartDate">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">无效时间<span class="required">*</span></span>
                        <div class="controls" id="txtEndDate">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">资格类别<span class="required">*</span></span>
                        <div class="controls" id="txtCertificateType">
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">资格证证<span class="required">*</span></span>
                        <div class="controls">
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td>
                                        <div id="Div1">
                                            <img id="txtCertImg" src="/themes/Style1/Image/u_head_110x110.png" for="" />
                                        </div>
                                    </td>
                                    <td style="padding: 3px;"></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div style="text-align: center; margin-top: 20px;">
                        <input type="button" onclick="editCertInfo();" class="releaseBtn" style="margin-right: 20px;" value="编辑" />
                    </div>
                </div>
            </div>
            <div class="main-Info" id="mainInfo" style="margin-bottom: 200px; display: none;">
                <div class="main-horizontal">
                    <div class="r_row">
                        <span class="control-span">资格证号<span class="required">*</span></span><div class="controls">
                            <input type="text" id="certificateNumber" class="input titleInput" />
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">姓名<span class="required">*</span></span>
                        <div class="controls">
                            <input type="text" id="name" class="input titleInput" />
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">性别<span class="required">*</span></span>
                        <div class="controls">
                            <input type="radio" name="gender" checked="checked" value="1" />
                            男
                            <input type="radio" name="gender" value="0" />
                            女
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">国籍<span class="required">*</span></span>
                        <div class="controls">
                            <select id="nationId" class="input titleInput">
                                <option value="DF6723BE-A25C-4F77-BB49-A1662D3E6F2A">中国</option>
                            </select>
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">住址<span class="required">*</span></span>
                        <div class="controls">
                            <select class="selArea" id="selCountry">
                                <option value="DF6723BE-A25C-4F77-BB49-A1662D3E6F2A">中国</option>
                                <option value="453370FE-8295-41EC-A41C-B6F650AD1B4C">亚洲</option>
                                <option value="927D5F28-C4FB-46A9-940C-B07DF0A04018">北美洲</option>
                                <option value="1FEAF456-7C76-41C8-A3D0-F9C12415A736">南美洲</option>
                                <option value="4E2B4524-E9CB-4E20-9224-E58EB636D1C7">非洲</option>
                                <option value="67FA6A8D-951C-4B53-AE1E-70DCB97E11DE">欧洲</option>
                                <option value="0B772F3D-D8F8-42E3-9019-81FE6F772236">大洋洲</option>
                            </select>
                            <select class="selArea" id="selCity">
                                <option value="">请选择</option>
                            </select>
                            <select class="selArea" id="selDestination">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">出生日期<span class="required">*</span></span>
                        <div class="controls">
                            <input type="text" id="birthDate" onclick="laydate({ min: '1099-06-16 23:59:59', max: laydate.now(), format: 'YYYY-MM-DD' })" class="laydate-icon input titleInput" />
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">领证日期<span class="required">*</span></span>
                        <div class="controls">
                            <input type="text" id="issueDate" onclick="laydate({ min: '1099-06-16 23:59:59', max: laydate.now(), format: 'YYYY-MM-DD' })" class="laydate-icon input titleInput" />
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">准驾车型<span class="required">*</span></span>
                        <div class="controls">
                            <select id="quasiType" class="input titleInput">
                                <option value="A1">A1</option>
                                <option value="A2">A2</option>
                                <option value="A3">A3</option>
                                <option value="B1">B1</option>
                                <option value="B2">B2</option>
                                <option value="C1">C1</option>
                                <option value="C2">C2</option>
                            </select>
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">起效日期<span class="required">*</span></span>
                        <div class="controls">
                            <input type="text" id="effStartDate" class="laydate-icon input titleInput" />
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">无效时间<span class="required">*</span></span>
                        <div class="controls">
                            <input type="text" id="endDate" class="laydate-icon input titleInput" />
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">资格类别<span class="required">*</span></span>
                        <div class="controls">
                            <input type="text" id="certificateType" class="input titleInput" />
                        </div>
                    </div>
                    <div class="r_row">
                        <span class="control-span">资格证证<span class="required">*</span></span>
                        <div class="controls">
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td>
                                        <div id="logo_img_selected">
                                            <img id="uHeadImg" src="/themes/Style1/Image/u_head_110x110.png" for="" />
                                        </div>
                                    </td>
                                    <td style="padding: 3px;">
                                        <div style="padding: 5px;">
                                            <a id="btnupImg" target="_self" value="上传图片" style="margin: 6px; cursor: pointer;" onclick="javascript:return false;">上传图片</a>
                                            <p>
                                                文件大小不能大于1M
                                            </p>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div style="text-align: center; margin-top: 20px;">
                        <input type="button" onclick="saveCerificate();" class="releaseBtn" style="margin-right: 20px;" value="保存" />
                        <input type="button" onclick="cancelEdit()" class="releaseBtn" style="margin-right: 20px;" value="取消" />
                    </div>
                </div>
            </div>
        </div>
        <!--start JS引用-->
        <script src="/jqPlugin/js/jquery-1.8.3.min.js"></script>
        <script src="/jqPlugin/js/jBase.js"></script>
        <script src="/jqPlugin/js/jBPage.js"></script>
        <script src="/jqPlugin/js/laytpl.js"></script>
        <script src="/jqPlugin/layer/layer.min.js"></script>
        <script src="/jqPlugin/laydate/laydate.js" type='text/javascript'></script>

        <script src="/themes/wStyle1/js/comm/VerifyJs.js"></script>
        <script src="/jqPlugin/SelectSimu/js/SelectSimu.js"></script>
        <script src="/themes/wStyle1/js/comm/jsLayout.js"></script>
        <script src="/themes/wStyle1/js/comm/DateInfo.js"></script>

        <!--end JS引用-->
        <script type="text/javascript">
            var end = {
                elem: '#endDate',
                format: 'YYYY-MM-DD',
                min: '1099-06-16 23:59:59', //设定最小日期为当前日期
                max: '2399-06-16 23:59:59', //最大日期
                istime: true,
                istoday: false,
                choose: function (datas) {
                    //start.max = datas; //结束日选好后，重置开始日的最大日期
                    start.start = datas //将结开始的初始值设定为开始日
                    computingPrice();
                }
            };
            var start = {
                elem: '#effStartDate',
                format: 'YYYY-MM-DD',
                min: '1099-06-16 23:59:59', //设定最小日期为当前日期
                max: laydate.now(), //最大日期
                istime: true,
                istoday: false,
                choose: function (datas) {
                    end.min = datas; //开始日选好后，重置结束日的最小日期
                    end.start = datas //将结束日的初始值设定为开始日
                }
            };
            laydate(start);

            laydate(end);
            $(function () {
                $.ploadFile("kindeditor", function (script, textStatus) {
                    $.setUploadFile('btnupImg', { FileId: '', RelId: "", rType1: '0', rType2: '' }, function (data) {
                        if (data.url) {
                            $('#logo_img_selected').empty().html('<img alt="" src="' + data.url + '" for="' + data.url + '">');
                        }
                    });
                });
            });

            (function () {
                var djackId = GetQueryStr("djackId");
                $("#selCountry").find("option[value='DF6723BE-A25C-4F77-BB49-A1662D3E6F2A']").attr("selected", "selected");
                $("#djackId").val(djackId);
                btnDo("init");

            })();

            $("#selCountry").change(function () {
                btnDo("upCountry")
            });
            $("#selCity").change(function () {
                btnDo("upCity");
            })

            function btnDo(sEbtn) {
                GtGrid1Action = sEbtn;
                var opart = new jsonRow();
                if (sEbtn == "init") {
                    opart.AddCell("parentsId", "DF6723BE-A25C-4F77-BB49-A1662D3E6F2A");
                    opart.AddCell("djackId", $("#djackId").val());
                }
                else if (sEbtn == "upCountry") {
                    opart.AddCell("parentsId", $.trim($("#selCountry").val()));
                }
                else if (sEbtn == "upCity") {
                    opart.AddCell("parentsId", $.trim($("#selCity").val()));
                }
                opart.AddCell("ACTION", GtGrid1Action);
                ajaxComm(opart);
            }

            function setCertInfo(data) {
                $("#txtCertificateNumber").text(data.rows[0]["DOCUMENT_NO"]);
                $("#crtificateId").val(data.rows[0]["QUALIFICATION_CERTIFICATE_ID"]);
                $("#txtName").text(data.rows[0]["REAL_NAME"]);
                $("#txtGender").text(data.rows[0]["GENDER"] == "True" ? "男" : "女");
                $("#txtGender").attr("data-value", data.rows[0]["GENDER"] == "True" ? "1" : "0");
                $("#txtNationId").text(data.rows[0]["NATIONLITY_NAME"]);
                $("#txtNationId").attr("data-value", data.rows[0]["NATIONLITY_ID"]);
                $("#txtSelCountry").text(data.rows[0]["COUNTRY_NAME"]);
                $("#txtSelCountry").attr("data-value", data.rows[0]["COUNTRY_ID"]);
                $("#txtSelCity").text(data.rows[0]["CITY_NAME"]);
                $("#txtSelCity").attr("data-value", data.rows[0]["CITY_ID"]);
                $("#txtSelDestination").text(data.rows[0]["AREA_NAME"]);
                $("#txtSelDestination").attr("data-value", data.rows[0]["AREA_ID"]);
                $("#txtBirthDate").text(formatDate(new Date(data.rows[0]["BIRTH_DATE"]), false));
                $("#txtIssueDate").text(formatDate(new Date(data.rows[0]["ISSUE_DATE"]), false));
                $("#txtQuasiType").text(data.rows[0]["QUASI_DRIVING_VEHICLE"]);
                $("#txtEffStartDate").text(formatDate(new Date(data.rows[0]["VALID_START_DATE"]), false));
                $("#txtEndDate").text(formatDate(new Date(data.rows[0]["VALIDITY"]), false));
                $("#txtCertificateType").text(data.rows[0]["QUALIFICATION_CATEGORY"]);
                $("#txtCertImg").attr("src", data.rows[0]["DOCUMENT_IMAGE"]);
                $("#txtCertImg").attr("for", data.rows[0]["DOCUMENT_IMAGE"]);
            }

            function editCertInfo() {
                $("#certificateNumber").val($("#txtCertificateNumber").text());
                $("#name").val($("#txtName").text());
                $("input[name='gender'][value='" + $("#txtGender").attr("data-value") + "']").attr("checked", "checked");
                $("#nationId").val($("#txtNationId").attr("data-value"));
                if ($("#selCountry").find("option[value='" + $("#txtSelCountry").attr("data-value") + "']").length < 1 || $("#selCity").find("option[value='" + $("#txtSelCity").attr("data-value") + "']").length < 1 || $("#selDestination").find("option[value='" + $("#txtSelDestination").attr("data-value") + "']").length < 1) {
                    $("#selCountry").val($("#txtSelCountry").attr("data-value"));
                    var opart = new jsonRow();
                    opart.AddCell("parentsId", $("#txtSelCountry").attr("data-value"));
                    opart.AddCell("cityId", $("#txtSelCity").attr("data-value"));
                    opart.AddCell("destionId", $("#txtSelDestination").attr("data-value"));
                    opart.AddCell("ACTION", "editCertificate");
                    ajaxComm(opart);
                } else {
                    $("#selCountry").val($("#txtSelCountry").attr("data-value"));
                    $("#selCity").val($("#txtSelCity").attr("data-value"));
                    $("#selDestination").val($("#txtSelDestination").attr("data-value"));
                }
                $("#birthDate").val($("#txtBirthDate").text());
                $("#endDate").val($("#txtEndDate").text());
                $("#issueDate").val($("#txtIssueDate").text());
                $("#quasiType").val($("#txtQuasiType").text());
                $("#effStartDate").val($("#txtEffStartDate").text());
                $("#certificateType").val($("#txtCertificateType").text());
                $("#uHeadImg").attr("src", $("#txtCertImg").attr("src"));
                $("#uHeadImg").attr("for", $("#txtCertImg").attr("src"));
                $("#txtMainInfo").hide();
                $("#mainInfo").show();
            }

            function cancelEdit() {
                $("#txtMainInfo").show();
                $("#mainInfo").hide();
            }

            function setSelect(inpuId, data) {
                if (IsNull(data)) {
                    return;
                }
                var select = $("#" + inpuId);
                select.html("");
                for (var i = 0; i < data.rows.length; i++) {
                    select.append("<option value='" + data.rows[i]["enum_Value"] + "'>" + data.rows[i]["enum_Name"] + "</option>")
                }

            }

            //显示地区
            function setCity(data, selectId, selectCity) {
                if (IsNull(data) || data.rows.length < 1) {
                    return;
                }
                $("#" + selectId).html("");
                var cityName = "";
                for (var i = 0; i < data.rows.length; i++) {
                    if (data.rows[i].COUNTRY_CITY_ID == selectCity) {
                        $("#" + selectId).append("<option selected='selected' value='" + data.rows[i].COUNTRY_CITY_ID + "'>" + data.rows[i].COUNTRY_CITY_NME + "</option>");
                        cityName = data.rows[i].COUNTRY_CITY_NME;
                    } else {
                        $("#" + selectId).append("<option value='" + data.rows[i].COUNTRY_CITY_ID + "'>" + data.rows[i].COUNTRY_CITY_NME + "</option>");
                    }
                }
                if (IsNull(cityName)) {
                    cityName = data.rows[0].COUNTRY_CITY_NME;
                }
            }

            function setSelect(inpuId, data) {
                if (IsNull(data)) {
                    return;
                }
                var select = $("#" + inpuId);
                select.html("");
                for (var i = 0; i < data.rows.length; i++) {
                    select.append("<option value='" + data.rows[i]["enum_Value"] + "'>" + data.rows[i]["enum_Name"] + "</option>")
                }

            }

            //执行AJAX调用时获取参数
            function saveCerificate() {


                //证件id
                var crtificateId = $.trim($("#crtificateId").val());
                if (IsNull(crtificateId)) {
                    layer.alert('资格证id不能为空', 3);
                    return;
                }

                //证件号
                var certificateNumber = $.trim($("#certificateNumber").val());
                if (IsNull(certificateNumber)) {
                    layer.alert('请填写资格证号', 3);
                    return;
                }

                if (certificateNumber.length > 30) {
                    layer.alert("驾驶证号不能超过30个字符", 3);
                    return;
                }
                //姓名
                var name = $.trim($("#name").val());
                if (IsNull(name)) {
                    layer.alert('姓名不能为空', 3);
                    return;
                }
                if (name.length > 20) {
                    layer.alert("姓名不能超过20个字符", 3);
                    return;
                }
                //性别
                var gender = $("input[name='gender']:checked").val();
                //国籍id
                var nationId = $.trim($("#nationId").val());
                if (IsNull(nationId)) {
                    layer.alert('国籍不能为空', 3);
                    return;
                }
                //国籍名称
                var nationName = $.trim($("#nationId").find("option:selected").text());
                if (IsNull(nationName)) {
                    layer.alert('国籍不能为空', 3);
                    return;
                }
                var countryId = $.trim($("#selCountry").val());

                var countryName = $.trim($("#selCountry").find("option:selected").text());
                var cityId = $.trim($("#selCity").val());
                var cityName = $.trim($("#selCity").find("option:selected").text());
                var destinationId = $.trim($("#selDestination").val());
                var destinationName = $.trim($("#selDestination").find("option:selected").text());
                if (IsNull(countryId) || IsNull(countryName) || IsNull(cityId) || IsNull(cityName) || IsNull(destinationId) || IsNull(destinationName)) {
                    layer.alert('请选择住址', 3);
                    return;
                }
                //生日
                var birthDate = $.trim($("#birthDate").val());
                if (IsNull(birthDate)) {
                    layer.alert("出生日期不能为空", 3);
                    return;
                }
                //if (!IsPositiveFloat(price)) {
                //    layer.alert("价格只能是数字", 3);
                //    return;
                //}
                //领证日期
                var issueDate = $.trim($("#issueDate").val());
                if (IsNull(issueDate)) {
                    layer.alert("领证日期不能为空", 3);
                    return;
                }
                //驾照类型
                var quasiType = $("#quasiType").val();
                if (IsNull(quasiType)) {
                    layer.alert("驾照类型不能为空", 3);
                    return;
                }
                //有效日期
                var effStartDate = $.trim($("#effStartDate").val());
                if (IsNull(effStartDate)) {
                    layer.alert("起效日期不能为空", 3);
                    return;
                }
                //无效日期
                var endDate = $.trim($("#endDate").val());
                if (IsNull(endDate)) {
                    layer.alert('无效日期不能为空', 3);
                    return;
                }
                //资格类别
                var certificateType = $.trim($("#certificateType").val());
                if (IsNull(certificateType)) {
                    layer.alert('资格类别不能为空', 3);
                    return;
                }
                if (certificateType.length > 18) {
                    layer.alert('资格证类别最多不能超过18个字符', 3);
                    return;
                }
                //驾驶证图片
                var certificatePicture = $("#logo_img_selected").children().eq(0).attr("for");
                if (IsNull(certificatePicture)) {
                    layer.alert('请选择驾驶证图片', 3);
                    return;
                }
                layer.load('正在保存中…', 3);
                var _jsParam = new jsonRow();


                _jsParam.AddCell("crtificateId", crtificateId);
                _jsParam.AddCell("certificateNumber", certificateNumber);
                _jsParam.AddCell("certificatePicture", certificatePicture);

                _jsParam.AddCell("name", name);
                _jsParam.AddCell("gender", gender);
                _jsParam.AddCell("nationId", nationId);

                _jsParam.AddCell("nationName", nationName);
                _jsParam.AddCell("countryId", countryId);
                _jsParam.AddCell("countryName", countryName);
                _jsParam.AddCell("cityId", cityId);
                _jsParam.AddCell("cityName", cityName);
                _jsParam.AddCell("destinationId", destinationId);
                _jsParam.AddCell("destinationName", destinationName);
                _jsParam.AddCell("birthDate", birthDate);
                _jsParam.AddCell("issueDate", issueDate);
                _jsParam.AddCell("quasiType", quasiType);
                _jsParam.AddCell("effStartDate", effStartDate);
                _jsParam.AddCell("endDate", endDate);
                _jsParam.AddCell("certificateType", certificateType);
                _jsParam.AddCell("ACTION", "saveCerificate");

                ajaxComm(_jsParam);
            };
            function success() {
                layer.alert('修改成功', 1);
                setTimeout(function () {
                    location.reload();
                }, 2000);
            }
        </script>
    </div>
</body>
</html>
